package com.macro.mall.controller;

import com.macro.mall.common.api.CommonPage;
import com.macro.mall.common.api.CommonResult;
import com.macro.mall.model.UmsCommunityAgent;
import com.macro.mall.param.AddCommunityAgentParam;
import com.macro.mall.service.CommunityAgentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(tags = "CommunityAgentController", description = "社区代理管理")
@RequestMapping("/community-agent")
public class CommunityAgentController {

    private final CommunityAgentService communityAgentService;

    @Autowired
    public CommunityAgentController(CommunityAgentService communityAgentService) {
        this.communityAgentService = communityAgentService;
    }

    @ApiOperation("获取所有的团长")
    @GetMapping(value = "/listAll")
    public CommonResult<CommonPage<UmsCommunityAgent>> listAll(@RequestParam("pageNum") Integer pageNum) {
        List<UmsCommunityAgent> umsCommunityAgents = communityAgentService.listAll(20, pageNum);
        return CommonResult.success(CommonPage.restPage(umsCommunityAgents));
    }

    @ApiOperation("增加一个团长")
    @PostMapping("/add")
    public CommonResult<String> add(@Validated AddCommunityAgentParam addCommunityAgentParam){
        communityAgentService.addCommunityAgent(addCommunityAgentParam);
        return null;
    }

    @ApiOperation("增加一个团长")
    @PostMapping("/update")
    public CommonResult<String> update(@Validated AddCommunityAgentParam addCommunityAgentParam){
        communityAgentService.addCommunityAgent(addCommunityAgentParam);
        return null;
    }


}
